package com.atguigu.gmall.order.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@Data
@ConfigurationProperties(prefix = "gmall.pool")
public class ThreadPoolConfig {
    private Integer coresize;//: 100
    private Integer maxsize;//: 200
    private Integer queue;//: 200
    private Integer timeout;//: 2
    private ThreadPoolExecutor executor;
    @PostConstruct
    public void init(){
        executor = new ThreadPoolExecutor(coresize,
                maxsize,timeout , TimeUnit.MINUTES , new ArrayBlockingQueue<>(queue),
                Executors.defaultThreadFactory() , new ThreadPoolExecutor.AbortPolicy());
    }

    public ThreadPoolExecutor executor(){
        return executor;
    }
}
